package pl.register.android.activities.correlation.builder;

import android.content.Context;
import android.widget.Button;
import pl.register.android.activities.correlation.logic.CorrelationStudentsPresenter;
import pl.register.android.homework.HomeworkTopic;
import pl.register.android.lesson.LessonProgram;
import pl.register.android.util.StringUtils;

import java.util.Date;

/**
 * @author Mateusz Strzelecki
 * @since 2013-05-01
 */
public class HomeworkDateEditorDialog extends DateDialogBuilder {

    private final Button btnSchedule;

    private final CorrelationStudentsPresenter presenter;


    private final LessonProgram lessonProgram;

    public HomeworkDateEditorDialog(Context context, LessonProgram lessonProgram, CorrelationStudentsPresenter presenter, Button btnSchedule) {
        super(context, lessonProgram.getHomeworkDate(), createDialogMsg(lessonProgram));
        this.lessonProgram = lessonProgram;
        this.presenter = presenter;
        this.btnSchedule = btnSchedule;
    }

    private static String createDialogMsg(LessonProgram lessonProgram) {
        HomeworkTopic homeworkTopic = lessonProgram.getHomeworkTopic();
        return StringUtils.build("Proszę wybrać nowy termin pracy domowej: \n'", homeworkTopic.getTopic(),"'");
    }

    @Override
    protected void settleNewDate(Date newDate) {
        lessonProgram.setHomeworkDate(newDate);
        btnSchedule.setText(lessonProgram.getHomeworkDateInString());
        presenter.updateLessonProgram(lessonProgram);
    }
}
